package KasirKasur;

public class Kasir implements Runnable {
	private RunNumberGenerator generator;
		
	public Kasir(RunNumberGenerator generator){
		super();
		this.generator = generator;
	}
	
	public void BikinKuitansi(){
		if (Thread.currentThread().getName().contains("Thread-2") ){
			Thread.currentThread().setName("Kasir 3");
		}else if (Thread.currentThread().getName().contains("Thread-0") ){
			Thread.currentThread().setName("Kasir 1");
		}else if (Thread.currentThread().getName().contains("Thread-1") ){
			Thread.currentThread().setName("Kasir 2");
		}
		
		synchronized (generator) {
			System.out.println(Thread.currentThread().getName() + " kuitansi : " + generator.Generator());
		}
	}
	
	public void run(){
		for (int i=0; i<10; i++){
			BikinKuitansi();
		}
	}
}
